Learn R Programming

energy (version 1.7-11)

Distance Matrix: Distance Matrices

Description

Utilities for working with distance matrices. is.dmatrix is a utility that checks whether the argument is a distance or dissimilarity matrix; is it square symmetric, non-negative, with zero diagonal? calc_dist computes a distance matrix directly from a data matrix.

Usage

is.dmatrix(x, tol = 100 * .Machine$double.eps)
calc_dist(x)

Value

is.dmatrix returns TRUE if (within tolerance) x is a distance/dissimilarity matrix; otherwise FALSE. It will return FALSE if x is a class dist object.

calc_dist returns the Euclidean distance matrix for the data matrix x, which has observations in rows.

Arguments

x

numeric matrix

tol

tolerance for checking required conditions

Author

Maria L. Rizzo mrizzo@bgsu.edu

Details

Energy functions work with the distance matrices of samples. The is.dmatrix function is used internally when converting arguments to distance matrices. The default tol is the same as default tolerance of isSymmetric.

calc_dist is an exported Rcpp function that returns a Euclidean distance matrix from the input data matrix.

References

Szekely, G.J. and Rizzo, M.L. (2014), Partial Distance Correlation with Methods for Dissimilarities. Annals of Statistics, Vol. 42 No. 6, 2382-2412.

Examples

Run this code
x <- matrix(rnorm(20), 10, 2)
D <- calc_dist(x)
is.dmatrix(D)
is.dmatrix(cov(x))

Run the code above in your browser using DataLab